var app = getApp()
Page({

  /** 
   * 页面的初始数据
   */
  data: {
    TabCur: 0,
    cardCur: 0,
    swiperList: '',
    swiper: [{
        id: 1,
        photourl: '../../static/banner/banner1.jpg'
      },
      {
        id: 1,
        photourl: '../../static/banner/banner2.jpg'
      }
    ],
    tuijian: '',
    youhui: '',
    ershou: '',
    zaixian: '',
    showmenu1: true,
    showmenu2: true,
    showmenu3: true,
    showmenu4: true,
    areatype: 1, //默认是1 地区和学校的区分
    msgList: [{
        key: 1,
        name: '区域'
      },
      {
        key: 2,
        name: '类型'
      },
      {
        key: 3,
        name: '价格'
      },
      {
        key: 4,
        name: '筛选'
      }
    ],
    areaul: [{
        key: 1,
        active: true,
        name: '区域'
      },
      {
        key: 2,
        active: false,
        name: '学区'
      },
    ],
    arrschool: '',
    arealist: '',
    schoollist: '',
    studyarea: [{
        key: 1,
        active: true,
        name: '不限'
      },
      {
        key: 2,
        active: false,
        name: '合肥一中'
      },
      {
        key: 3,
        active: false,
        name: '肥西三中'
      },
      {
        key: 4,
        active: false,
        name: '合肥市青年小学'
      },
    ],
    menu2_list: [{
        key: 1,
        active: true,
        name: '不限',
        property_type: ''
      },
      {
        key: 2,
        active: false,
        name: '住宅',
        property_type: 1
      },
      {
        key: 3,
        active: false,
        name: '商铺',
        property_type: 2
      },
      {
        key: 4,
        active: false,
        name: '写字楼',
        property_type: 3
      },
      {
        key: 5,
        active: false,
        name: '别墅',
        property_type: 4
      },
      {
        key: 6,
        active: false,
        name: '公寓',
        property_type: 5
      },
      {
        key: 7,
        active: false,
        name: '其他',
        property_type: 6
      },
    ],
    price_list: [{
        key: 1,
        active: true,
        name: '不限',
        low_price: '1',
        high_price: '300000000'
      },
      {
        key: 2,
        active: false,
        name: '7000以下',
        low_price: '1',
        high_price: '7000'
      },
      {
        key: 3,
        active: false,
        name: '7000-8000',
        low_price: '7000',
        high_price: '8000'
      },
      {
        key: 4,
        active: false,
        name: '8000-10000',
        low_price: '8000',
        high_price: '10000'
      },
      {
        key: 5,
        active: false,
        name: '10000-12000',
        low_price: '10000',
        high_price: '12000'
      },
      {
        key: 6,
        active: false,
        name: '12000-15000',
        low_price: '12000',
        high_price: '15000'
      },
      {
        key: 7,
        active: false,
        name: '15000-18000',
        low_price: '15000',
        high_price: '18000'
      },
      {
        key: 8,
        active: false,
        name: '18000-20000',
        low_price: '18000',
        high_price: '20000'
      },
      {
        key: 9,
        active: false,
        name: '20000以上',
        low_price: '20000',
        high_price: '300000000'
      },
    ],
    sort: [{
        key: 1,
        active: true,
        name: '不限',
        sort_field: 'sort',
        order: 'desc'
      },
      {
        key: 2,
        active: false,
        name: '默认排序',
        sort_field: 'sort',
        order: 'desc'
      },
      {
        key: 3,
        active: false,
        name: '价格由高到低',
        sort_field: 'averagePrice',
        order: 'desc'
      },
      {
        key: 4,
        active: false,
        name: '价格由低到高',
        sort_field: 'averagePrice',
        order: 'asc'
      },
      {
        key: 5,
        active: false,
        name: '人气由高到低',
        sort_field: 'hits',
        order: 'desc'
      },
      {
        key: 6,
        active: false,
        name: '人气由低到高',
        sort_field: 'hits',
        order: 'asc'
      },
    ],
    sort_field: 'sort',
    order: 'desc',
    huxing: [{
        key: 1,
        active: true,
        name: '不限',
        bedroom: ''
      },
      {
        key: 2,
        active: false,
        name: '一室',
        bedroom: '1'
      },
      {
        key: 3,
        active: false,
        name: '二室',
        bedroom: '2'
      },
      {
        key: 4,
        active: false,
        name: '三室',
        bedroom: '3'
      },
      {
        key: 5,
        active: false,
        name: '四室',
        bedroom: '4'
      },
      {
        key: 6,
        active: false,
        name: '五室',
        bedroom: '5'
      },
      {
        key: 7,
        active: false,
        name: '五室以上',
        bedroom: '6'
      },
    ],
    bedroom: '',

    mianji: [{
        key: 1,
        active: true,
      name: '不限'
      },
      {
        key: 2,
        active: false,
        name: '50㎡以下'
      },
      {
        key: 3,
        active: false,
        name: '50-70㎡'
      },
      {
        key: 4,
        active: false,
        name: '70-90㎡'
      },
      {
        key: 5,
        active: false,
        name: '90-110㎡'
      },
      {
        key: 6,
        active: false,
        name: '110-150㎡'
      },
      {
        key: 7,
        active: false,
        name: '150-200㎡'
      },
      {
        key: 8,
        active: false,
        name: '200-300㎡'
      },
      {
        key: 9,
        active: false,
        name: '300㎡以上'
      },
    ],
    xsmj: '',
    tese: [{
        key: 1,
        active: true,
        name: '不限'
      },
      {
        key: 2,
        active: false,
        name: '优惠'
      },
      {
        key: 3,
        active: false,
        name: '毛坯'
      },
      {
        key: 4,
        active: false,
        name: '简装'
      },
      {
        key: 5,
        active: false,
        name: '精装'
      },
      {
        key: 6,
        active: false,
        name: '公园地产'
      },
      {
        key: 7,
        active: false,
        name: '地铁盘'
      },
    ],
    park: '', // gongyuan
    renovate_state: '', //装修
    discount_info: '', // 类型 	
    subway_station: '', // 地铁盘
    tesetype: 1, // 0不限 1 类型 2 :装修 3:公园 4 地铁盘
    kaipan: [{
        key: 1,
        active: true,
        name: '不限'
      },
      {
        key: 2,
        active: false,
        name: '本月开盘'
      },
      {
        key: 3,
        active: false,
        name: '下月开盘'
      },
      {
        key: 4,
        active: false,
        name: '近3个月开盘'
      },
      {
        key: 5,
        active: false,
        name: '半年内开盘'
      },
      {
        key: 6,
        active: false,
        name: '一年内开盘'
      },
    ],
    xiaoshou: [{
        key: 1,
        active: true,
        name: '不限',
        sale_state: ''
      },
      {
        key: 2,
        active: false,
        name: '待售',
        sale_state: 1
      },
      {
        key: 3,
        active: false,
        name: '在售',
        sale_state: 2
      },
      {
        key: 4,
        active: false,
        name: '尾盘',
        sale_state: 3
      },
      {
        key: 5,
        active: false,
        name: '售完',
        sale_state: 4
      },

    ],
    sale_state: '', // 销售状态
    kaifashang: [{
        key: 1,
        active: true,
        name: '不限'
      },
      {
        key: 2,
        active: false,
        name: '万科'
      },
      {
        key: 3,
        active: false,
        name: '保利'
      },
      {
        key: 4,
        active: false,
        name: '绿地'
      },
      {
        key: 5,
        active: false,
        name: '恒大'
      },
      {
        key: 6,
        active: false,
        name: '华润'
      },
      {
        key: 7,
        active: false,
        name: '文一'
      },
      {
        key: 8,
        active: false,
        name: '万达'
      },
      {
        key: 9,
        active: false,
        name: '华邦'
      },
      {
        key: 10,
        active: false,
        name: '中海'
      },
      {
        key: 11,
        active: false,
        name: '信达'
      },

    ],
    searchvalue: '', // 输入框内容
    // 111222
    low_price: '', // 价格 低价
    high_price: '', // 价格 高价
    property_type: '', // 类型
    space_type: '', // 区域类型： 1 ：地区 2： 学校
    space_id: '', // 地区或者学校的id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  searchlist(e) {
    this.setData({
      searchvalue: e.detail.value
    })

  }, //搜索框内容
  searchdesc() {
    var that = this;
    var setid = app.globalData.cityCode;
    var searchvalue = that.data.searchvalue;
    if (searchvalue == '') {
      wx.showToast({
        title: '请输入内容',
        duration: 1000,
        icon: 'none'
      })
    } else {
      wx.showLoading({            
        title: '加载中',
                  
      })
      app.core('get', 'search_loupan_by_name/site_id/' + setid + '', {
        project_name: searchvalue
      }, (res) => {
        console.log(res)
        if (res.data.houses == '' && res.data.oldhouses == '') {
          wx.showToast({
            title: '暂无相关信息',
            duration: 1000,
            icon: 'none'
          })
        } else {
          wx.navigateTo({
            url: './searchlist?content=' + searchvalue + '',
          })
        }
        wx.hideLoading()
      })
    }

  },

  onLoad: function(options) {
    var that = this;
    that.httpsgetarea(); // 获取地区/类型
    this.tuijian(); // 推荐楼盘
    this.guanggao(); //广告banner
    that.youhui(); // 优惠楼盘
    that.ershou(); //二手loupa
    that.zaixian(); // 在线选房

    var arealist = that.data.arealist;
    that.setData({
      arrschool: arealist
    })
  },
  guanggao() {
    var that = this; 
    var setid = app.globalData.cityCode;
    wx.showLoading({            
      title: '加载中',
                
    })
    app.core('get', 'get_advert/site_id/' + setid + '', '', (res) => {

      that.setData({
        swiperList: res.data
      })
      wx.hideLoading()
    })
  },
  tuijian(id) {
    var that = this;
    var setid = app.globalData.cityCode;
    wx.showLoading({
      title: '加载中',
    })

    app.core('get', 'get_home_houses/site_id/' + setid + '', {},
      (res) => {
        console.log(res, 'tuijian')

        wx.hideLoading()

        that.setData({
          tuijian: res.data
        })
      }
    )
  },
  // 推荐楼盘

  // 地区筛选
  youhui() {
    var that = this;
    var setid = app.globalData.cityCode;
    wx.showLoading({
      title: '加载中',
    })
    app.core('get', 'get_youhui_houses_list/site_id/' + setid + '', {},
      (res) => {
        console.log(res, 'youhui')
        that.setData({
          youhui: res.data
        })
        wx.hideLoading()
      }
    )
  }, //优惠楼盘

  ershou() {
    var that = this;
    var setid = app.globalData.cityCode;
    wx.showLoading({
      title: '加载中',
    })
    app.core('get', 'get_old_houses_list/site_id/' + setid + '', {},
      (res) => {
        console.log(res, 'ershou')
        var arr = res.data;
        for (var i = 0; i < arr.length; i++) {
          switch (arr[i].propertyType) {
            case 1:
              arr[i].propertyType = '住宅'
              break;
            case 2:
              arr[i].propertyType = '商铺'
              break;
            case 3:
              arr[i].propertyType = '写字楼'
              break;
          }

          if (arr[i].fitment == 1) {
            arr[i].fitment = '毛坯'
          } else if (arr[i].fitment == 2) {
            arr[i].fitment = '普通装修'
          } else if (arr[i].fitment == 3) {
            arr[i].fitment = '精装修'
          } else {
            arr[i].fitment = '其他'
          }
        }
        that.setData({
          ershou: arr
        })
        wx.hideLoading()
      }
    )
  }, // 二手楼盘
  /**
   * 生命周期函数--监听页面初次渲染完成
   */

  // 在线选房

  zaixian() {
    var that = this;
    var setid = app.globalData.cityCode;
    wx.showLoading({
      title: '加载中',
    })
    app.core('get', 'get_sale_online_list/site_id/' + setid + '/limit/5', '', (res => {
      console.log(res, '在线选房')
      that.setData({
        zaixian: res.data
      })
      wx.hideLoading()
    }))
  },

  onReady: function() {
    var that = this;

  },


  // 菜单
  httpsgetarea() {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    var setid = app.globalData.cityCode; // 城市id

    app.core('get', 'get_search_condition/site_id/' + setid + '', '', (res => {
      console.log(res)


      var newarea = [];
      var area = res.data.areas;
      for (var i = 0; i < area.length; i++) {
        newarea.push(area[i])
        newarea[i].active = false;
        newarea[i].name = area[i].areaName
      }
      var area_fir = {
        name: '不限',
        active: true
      }
      newarea.unshift(area_fir)
      console.log(newarea, 'newarea')
      that.setData({
        arrschool: newarea,
        arealist: newarea
      })
      // 区县结束

      // 学区开始
      var school = res.data.schools;
      var newschool = [];
      for (var i = 0; i < school.length; i++) {
        newschool.push(school[i])
        newschool[i].active = false;

      }
      var school_fir = {
        name: '不限',
        active: true
      }
      newschool.unshift(school_fir)
      console.log(newschool, 'newschool')
      that.setData({
        schoollist: newschool
      })

      // 类型开始
      var housetype = res.data.types;
      var newtype = [];
      for (var i = 0; i < housetype.length; i++) {
        newtype.push(school[i])
        newtype[i].active = false;
      }
      var type_fir = {
        name: '不限',
        active: true
      }
      newtype.unshift(school_fir)
      that.setData({
        schoollist: newschool
      });
      wx.hideLoading()
    }))
  },
  // 请求后台获取地区或者学区


  checkschool(e) {

    var that = this;
    var index = e.target.dataset.index;
    var arr = that.data.areaul;
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true;
      } else {
        arr[i].active = false
      }
    }
    //11111111
    var arealist = that.data.arealist;
    var schoollist = that.data.schoollist;
    console.log(index)
    if (index == 1) {
      that.setData({
        arrschool: schoollist,
        areatype: 2 // xuexiao
      }) // xuexiao
    } else {
      that.setData({
        arrschool: arealist,
        areatype: 1 // diqu
      }) // diqu 
    }
    console.log(arr, index)
    that.setData({
      areaul: arr
    })

  },

  checkareass(e) {
    // 地区筛选列表 
    var that = this;
    var index = e.target.dataset.index;
    var areatype = that.data.areatype; // 区分地区还是学校
    var id = e.target.dataset.id; // 地区id

    var arr = that.data.arealist; // 地区列表
    var school = that.data.schoollist; // 学校列表
    var name = '';
    if (areatype == 1) {
      arr = that.data.arealist;
      var area_id = arr[index].id;
      that.setData({
        space_type: 1, // 地区
        space_id: area_id, // id
      })
      that.tuijianarea(area_id, 1)
    } else {
      arr = that.data.schoollist;
      var school_id = arr[index].id;
      that.setData({
        space_type: 2, // 地区
        space_id: area_id, // id
      })
      that.tuijianarea(school_id, 2)
    }
    for (var i = 0; i < arr.length; i++) {
      if (i == index) {
        arr[index].active = true;
        name = arr[index].name;

      } else {
        arr[i].active = false
      }
    }
    var arrss = that.data.msgList;

    arrss[0].name = name;
    that.setData({

      msgList: arrss,
      showmenu1: true
    })


  },
  // 
  tuijianarea(id, type) {

    var that = this;
    var sort_field = that.data.sort_field;
    var order = that.data.order;
    // 排序
    var bedroom = that.data.bedroom;
    //户型
    var xsmj = that.data.xsmj;
    //面积
    var sale_state = that.data.sale_state;
    // 销售状态
    var renovate_state = that.data.renovate_state

    var low_price = that.data.low_price; // 低价
    var high_price = that.data.high_price; // 高价
    var property_type = that.data.property_type; // 类型
    var space_id = that.data.space_id; // 地区或者学校id
    var space_type = that.data.space_type; // 地区或者学校区分；


    wx.showLoading({
      title: '加载中',
    })
    var setid = app.globalData.cityCode;
    app.core('get', 'get_recommend_houses/site_id/' + setid + '/limit/5', {
        space_id: id,
        space_type: type,
        sort_field: sort_field,
        order: order,
        bedroom: bedroom,
        xsmj: xsmj,
        sale_state: sale_state,
        renovate_state: renovate_state,
        low_price: low_price,
        high_price: high_price,
        property_type: property_type

      },
      (res) => {
        console.log(res, 'tuijian')
        that.setData({
          tuijian: res.data
        })
        wx.hideLoading()
      }
    )


  },
  //  地区筛选
  checktype(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var property_type = e.currentTarget.dataset.property_type;
    var arr = that.data.menu2_list;
    var name = ''

    for (var i = 0; i < arr.length; i++) {
      if (i == index) {
        arr[index].active = true;
        console.log(index)
        name = arr[index].name
      } else {
        arr[i].active = false
      }
    }
    var arrss = that.data.msgList;

    arrss[1].name = name;
    that.setData({
      menu2_list: arr,
      msgList: arrss,
      showmenu2: true,
      property_type: property_type, // 类型
    })
    that.tuijiantype(property_type)
  },
  tuijiantype(e) {
    var that = this;
    var setid = app.globalData.cityCode;
    var areatype = that.data.areatype; //区域类型  2 ：学校 1 区域

    var sort_field = that.data.sort_field;
    var order = that.data.order;
    // 排序
    var bedroom = that.data.bedroom;
    //户型
    var xsmj = that.data.xsmj;
    //面积
    var sale_state = that.data.sale_state;
    // 销售状态
    var renovate_state = that.data.renovate_state

    var low_price = that.data.low_price; // 低价
    var high_price = that.data.high_price; // 高价
    var property_type = that.data.property_type; // 类型
    var space_id = that.data.space_id; // 地区或者学校id
    var space_type = that.data.space_type; // 地区或者学校区分；





    wx.showLoading({
      title: '加载中',
    })
    app.core('get', 'get_recommend_houses/site_id/' + setid + '/limit/5', {
        property_type: e,
        sort_field: sort_field,
        order: order,
        bedroom: bedroom,
        xsmj: xsmj,
        sale_state: sale_state,
        renovate_state: renovate_state,
        low_price: low_price,
        high_price: high_price,
        space_id: space_id,
        space_type: space_type,
      },
      (res) => {
        console.log(res, 'tuijian')
        that.setData({
          tuijian: res.data
        })
        wx.hideLoading()
      }
    )
  }, // 根据类型区分
  // 

  checkprice(e) {
    //价格筛选
    var that = this;
    var index = e.currentTarget.dataset.index;
    var low_price = e.currentTarget.dataset.lowprice;
    var high_price = e.currentTarget.dataset.highprice
    var arr = that.data.price_list;
    var name = ''
    var high_price = ''; // 最高 价
    var low_price = ''; // 最低价
    for (var i = 0; i < arr.length; i++) {
      if (i == index) {
        arr[index].active = true;
        console.log(index)
        name = arr[index].name;
        high_price = arr[index].high_price;
        low_price = arr[index].low_price;
      } else {
        arr[i].active = false
      }
      if (high_price && low_price) {
        //如果高价低价都存在的情况下，执行请求

      }
    }
    var arrss = that.data.msgList;

    arrss[2].name = name;
    that.setData({
      price_list: arr,
      msgList: arrss,
      showmenu3: true,
      low_price: low_price, // 低价
      high_price: high_price, // 高价
    })
    that.tuijianprice(low_price, high_price)
  },

  tuijianprice(low, high) {

    var that = this;
    var setid = app.globalData.cityCode;

    var sort_field = that.data.sort_field;
    var order = that.data.order;
    // 排序
    var bedroom = that.data.bedroom;
    //户型
    var xsmj = that.data.xsmj;
    //面积
    var sale_state = that.data.sale_state;
    // 销售状态
    var renovate_state = that.data.renovate_state

    var low_price = that.data.low_price; // 低价
    var high_price = that.data.high_price; // 高价
    var property_type = that.data.property_type; // 类型
    var space_id = that.data.space_id; // 地区或者学校id
    var space_type = that.data.space_type; // 地区或者学校区分；


    wx.showLoading({
      title: '加载中',
    })
    app.core('get', 'get_recommend_houses/site_id/' + setid + '/limit/5', {
        low_price: low,
        high_price: high,
        sort_field: sort_field,
        order: order,
        bedroom: bedroom,
        xsmj: xsmj,
        sale_state: sale_state,
        renovate_state: renovate_state,
        property_type: property_type,
        space_id: space_id,
        space_type: space_type
      },
      (res) => {
        console.log(res, 'tuijian')
        that.setData({
          tuijian: res.data
        })
        wx.hideLoading()
      }
    )
  }, // 价格推荐


  menuclickss(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var showmenu1 = that.data.showmenu1;
    var showmenu2 = that.data.showmenu2;
    var showmenu3 = that.data.showmenu3;
    var showmenu4 = that.data.showmenu4;
    console.log(index, showmenu1)

    if (index == 0) {
      that.setData({
        showmenu1: !showmenu1,
        showmenu2: true,
        showmenu3: true,
        showmenu4: true
      })
    } else if (index == 1) {
      that.setData({
        showmenu2: !showmenu2,
        showmenu1: true,
        showmenu3: true,
        showmenu4: true
      })
    } else if (index == 2) {
      that.setData({
        showmenu3: !showmenu3,
        showmenu1: true,
        showmenu2: true,
        showmenu4: true
      })
    } else if (index == 3) {
      that.setData({
        showmenu4: !showmenu4,
        showmenu1: true,
        showmenu2: true,
        showmenu3: true
      })
    }

  },

  checksort(e) {
    //筛选的排序
    var that = this;
    var index = e.currentTarget.dataset.index;
    var arr = that.data.sort;
    var sort_field = '';
    var order = ""
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true;
        sort_field = arr[i].sort_field;
        order = arr[i].order;
        that.setData({
          sort_field: sort_field,
          order: order
        })
      } else {
        arr[i].active = false
      }
    }
    that.setData({
      sort: arr
    })
  },
  checkhuxing(e) {
    // 筛选户型
    var that = this;
    var index = e.currentTarget.dataset.index;
    var arr = that.data.huxing;
    var bedroom = "";
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true
        bedroom = arr[i].bedroom;
        that.setData({
          bedroom: bedroom
        })
      } else {
        arr[i].active = false
      }
    }
    that.setData({
      huxing: arr
    })
  },

  // checkhuxing(e) {
  // 	var that = this;
  // 	var index = e.currentTarget.dataset.index;
  // 	var arr = that.data.huxing;
  // 	for (var i = 0; i < arr.length; i++) {
  // 		if (index == i) {
  // 			arr[i].active = true
  // 		} else {
  // 			arr[i].active = false
  // 		}
  // 	}
  // 	that.setData({
  // 		huxing: arr
  // 	})
  // },

  checkarea(e) {
    // 筛选面积
    var that = this;
    var index = e.currentTarget.dataset.index;
    var arr = that.data.mianji;
    var xsmj = "";
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true;
        xsmj = arr[i].name;
        if(xsmj == '不限'){
          that.setData({
            xsmj: ''
          })
        }else{
          that.setData({
            xsmj: xsmj
          })
        }
     
      } else {
        arr[i].active = false
      }
    }
    that.setData({
      mianji: arr
    })
  },


  checktese(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var arr = that.data.tese;
    var tese = '';
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true;


        if (arr[i].name == '毛坯') {
          tese = 1
        } else if (arr[i].name == '简装') {
          tese = 2
        } else if (arr[i].name == '精装') {
          tese = 3
        } else if (arr[i].name == '公园地产') {
          tese = 'park'
        } else if (arr[i].name == '地铁盘') {
          tese = 'subwayStation'
        } else if (arr[i].name == '优惠') {
          tese = 'discountInfo'
        }


        that.setData({
          tesetype: 2,
          renovate_state: tese
        })

        console.log(tese)
        // 判断装修情况



      } else {
        arr[i].active = false
      }
    }
    that.setData({
      tese: arr
    })
  },

  checkkaipan(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var arr = that.data.kaipan;
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true
      } else {
        arr[i].active = false
      }
    }
    that.setData({
      kaipan: arr
    })
  },

  checkxiaoshou(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var arr = that.data.xiaoshou;
    var sale_state = "";
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true;
        sale_state = arr[i].sale_state;
        that.setData({
          sale_state: sale_state
        })
      } else {
        arr[i].active = false
      }
    }
    that.setData({
      xiaoshou: arr
    })
  },

  checkkaifashang(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var arr = that.data.kaifashang;
    for (var i = 0; i < arr.length; i++) {
      if (index == i) {
        arr[i].active = true
      } else {
        arr[i].active = false
      }
    }
    that.setData({
      kaifashang: arr
    })
  },
  yessubmit() {
    ///222111
    var that = this;
    var sort_field = that.data.sort_field;
    var order = that.data.order;
    // 排序
    var bedroom = that.data.bedroom;
    //户型
    var xsmj = that.data.xsmj;
    //面积
    var sale_state = that.data.sale_state;
    // 销售状态
    var renovate_state = that.data.renovate_state


    var discount_info = that.data.discount_info;
    var low_price = that.data.low_price; // 低价
    var high_price = that.data.high_price; // 高价
    var property_type = that.data.property_type; // 类型
    var space_id = that.data.space_id; // 地区或者学校id
    var space_type = that.data.space_type; // 地区或者学校区分；


    var data = ""

    data = {
      sort_field: sort_field,
      order: order,
      bedroom: bedroom,
      xsmj: xsmj,
      sale_state: sale_state,
      renovate_state: renovate_state,
      //  筛选 
      low_price: low_price, // 低价
      high_price: high_price, // 高价
      property_type: property_type, // 类型
      space_id: space_id, // 地区或者学校id
      space_type: space_type, // 地区或者学校区分；

    }


    that.shaixuantuijian(data)
    that.setData({
      showmenu4: true
    })
  },
  shaixuantuijian(data) {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    var setid = app.globalData.cityCode;
    app.core('get', 'get_recommend_houses/site_id/' + setid + '/limit/5', data,
      (res) => {
        console.log(res, 'tuijian')
        that.setData({
          tuijian: res.data
        })
        wx.hideLoading()
      }
    )
  }, //筛选多情况
  cancels() {
    var that = this;
    var sort = this.data.sort
    var huxing = this.data.huxing
    var area = this.data.mianji
    var tese = this.data.tese
    var kaipan = this.data.kaipan
    var xiaoshou = this.data.xiaoshou
    var kaifashang = this.data.kaifashang
    that.cancelsss(sort, 'sort')
    that.cancelsss(huxing, 'huxing')
    that.cancelsss(area, 'area')
    that.cancelsss(tese, 'tese')
    that.cancelsss(kaipan, 'kaipan')
    that.cancelsss(xiaoshou, 'xiaoshou')
    that.cancelsss(kaifashang, 'kaifashang')

    var sort_field = that.data.sort_field;
    var order = that.data.order;
    // 排序
    var bedroom = that.data.bedroom;
    //户型
    var xsmj = that.data.xsmj;
    //面积
    var sale_state = that.data.sale_state;
    // 销售状态
    var renovate_state = that.data.renovate_state 
    // 特色
    that.setData({
      sort_field: 'sort',
      order: 'desc',
      bedroom:'',
      xsmj:'',
      sale_state:'',
      renovate_state:''
    })

  },

  cancelsss(arr, e) {

    for (var i = 0; i < arr.length; i++) {
      arr[i].active = false;

    }
    arr[0].active = true;

    if (e == 'sort') {
      this.setData({
        sort: arr
      })
    } else if (e == 'huxing') {
      this.setData({
        huxing: arr
      })
    } else if (e == 'area') {
      this.setData({
        mianji: arr
      })
    } else if (e == 'tese') {
      this.setData({
        tese: arr
      })
    } else if (e == 'kaipan') {
      this.setData({
        kaipan: arr
      })
    } else if (e == 'xiaoshou') {
      this.setData({
        xiaoshou: arr
      })
    } else if (e == 'kaifashang') {
      this.setData({
        kaifashang: arr
      })
    }



  },
  //控制菜单显示隐藏
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

    var key = wx.getStorageSync('citykey');
    if (key == true) {
      this.onLoad();
    }
    console.log("全局cityCode");
    console.log(app.globalData.cityCode);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  }
})